package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Carrier;
import com.ruoyi.system.service.ICarrierService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 承运商Controller
 * 
 * @author ruoyi
 * @date 2024-12-13
 */
@RestController
@RequestMapping("/wms/carrier")
public class CarrierController extends BaseController
{
    @Autowired
    private ICarrierService carrierService;

    /**
     * 查询承运商列表
     */
    @PreAuthorize("@ss.hasPermi('wms:carrier:list')")
    @GetMapping("/list")
    public TableDataInfo list(Carrier carrier)
    {
        startPage();
        List<Carrier> list = carrierService.selectCarrierList(carrier);
        return getDataTable(list);
    }

    /**
     * 导出承运商列表
     */
    @PreAuthorize("@ss.hasPermi('wms:carrier:export')")
    @Log(title = "承运商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Carrier carrier)
    {
        List<Carrier> list = carrierService.selectCarrierList(carrier);
        ExcelUtil<Carrier> util = new ExcelUtil<Carrier>(Carrier.class);
        util.exportExcel(response, list, "承运商数据");
    }

    /**
     * 获取承运商详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:carrier:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carrierService.selectCarrierById(id));
    }

    /**
     * 新增承运商
     */
    @PreAuthorize("@ss.hasPermi('wms:carrier:add')")
    @Log(title = "承运商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Carrier carrier)
    {
        return toAjax(carrierService.insertCarrier(carrier));
    }

    /**
     * 修改承运商
     */
    @PreAuthorize("@ss.hasPermi('wms:carrier:edit')")
    @Log(title = "承运商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Carrier carrier)
    {
        return toAjax(carrierService.updateCarrier(carrier));
    }

    /**
     * 删除承运商
     */
    @PreAuthorize("@ss.hasPermi('wms:carrier:remove')")
    @Log(title = "承运商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carrierService.deleteCarrierByIds(ids));
    }
}
